//
//  TTRightSegViewCell.m
//  TaoTuo
//
//  Created by admin on 2019/8/20.
//  Copyright © 2019 admin. All rights reserved.
//

#import "LLRightSegViewCell.h"
#import "TTCategorySubModel.h"

@interface LLRightSegViewCell ()

@property (strong, nonatomic) UIImageView *leftImageView;
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *pinyinLabel;
@property (strong, nonatomic) UILabel *countLabel;
@property (nonatomic, strong) UILabel *rightBottomLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;

@end

@implementation LLRightSegViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.layer.cornerRadius = 5;
        [self setupSubviews];
        
    }
    return self;
}

- (void)setModel:(TTCategorySubModel *)model
{
    _model = model;
    self.backgroundColor = model.bgColor;
    self.leftImageView.image = [UIImage imageNamed:model.imageName];
    self.titleLabel.text = model.name;
    NSString *str = [NSString stringWithFormat:@"%d件", model.count];
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:str];
    [attr addAttributes:@{NSForegroundColorAttributeName : UIColorHex(333333), NSFontAttributeName : [UIFont systemFontOfSize:16]} range:[str rangeOfString:@"件"]];
    self.countLabel.attributedText = attr;
    
    self.pinyinLabel.text = model.pinyin;
    
    
}


- (void)setupSubviews
{
    _leftImageView = [[UIImageView alloc] init];
    _leftImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:_leftImageView];
    [_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(10);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
        make.width.mas_equalTo(80*kScale);
    }];
    
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(494949) fontSize:14];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.leftImageView.mas_right).mas_offset(10);
    }];
    
    _pinyinLabel = [UILabel labelWithTitle:@"" color:UIColorHex(999999) fontSize:11];
    [self.contentView addSubview:_pinyinLabel];
    [_pinyinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom);
    }];
    
    _countLabel = [UILabel labelWithTitle:@"" color:kMainColor font:[UIFont boldSystemFontOfSize:18]];
    [self.contentView addSubview:_countLabel];
    [_countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView).mas_offset(-10);
        make.centerX.equalTo(self.contentView).mas_offset(60);
    }];
    
    _rightArrowImageView = [[UIImageView alloc] init];
    _rightArrowImageView.image = [UIImage imageNamed:@"btn_right_arrow"];
    _rightArrowImageView.contentMode = UIViewContentModeCenter;
    [self.contentView addSubview:_rightArrowImageView];
    [_rightArrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.equalTo(self.contentView).mas_offset(-4);
        make.width.mas_equalTo(12);
        make.height.mas_equalTo(20);
    }];
    
    _rightBottomLabel = [UILabel labelWithTitle:@"现货库存" color:UIColorHex(999999) fontSize:11];
    [self.contentView addSubview:_rightBottomLabel];
    [_rightBottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.rightArrowImageView.mas_left);
        make.bottom.height.equalTo(self.rightArrowImageView);
    }];
    
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.y += 10;
    frame.origin.x += 10;
    
    frame.size.height -= 10;
    frame.size.width -= 20;
    
    [super setFrame:frame];
}




@end
